{-# OPTIONS -fglasgow-exts #-}
module Data.Transform.FormatEvolutionHUnit where

import HUnit
import Data.Transform.Coupled

-----------------------------------------------------------------------------

main = runTestTT . TestList . map TestCase $ [testAddfieldl]


-----------------------------------------------------------------------------

testAddfieldl :: IO ()
testAddfieldl = do
   let format = String :: Type String
   let evolve = addfieldl Int 0

   -- Test format evolution
   let (Just evolutedFormat) = evolve format   
   let expectedFormat = (Prod Int String) :: Type (Int,String)
   assertEqual "Transformed format not valid" (show expectedFormat) (showType evolutedFormat)
   
   -- Test forward migration
   let (Just fv) = forth evolutedFormat expectedFormat "test"
   assertEqual "Forward migration not valid" (0,"test") fv
   
   -- Test backwards migration
   let (Just bv) = back evolutedFormat expectedFormat (0,"test")
   assertEqual "Backward migration not valid" "test" bv
